package com.zs.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/6/10 上午11:48
 */
public class IntermediaryInvocationHandler implements InvocationHandler {

    private Object target; //被代理的目标对象，即其内部含有对真实主题的引用

    public void setTarget(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object feedback = method.invoke(target, args);
        after();
        return "看房记录：买家反馈“" + feedback + "”";
    }

    public void before() {
        System.out.println("前期准备。");
        System.out.println("查找房源。");
        System.out.println("和卖家沟通时间。");
    }

    public void after() {
        System.out.println("后期跟踪");
        System.out.println("和买家沟通意见");
    }
}
